import * as faceapi from "face-api.js";


main()

async function main(){
    // 加载模型权重文件
    await faceapi.nets.ssdMobilenetv1.loadFromUri('http://127.0.0.1:8888/weights/')
    await faceapi.nets.faceLandmark68Net.loadFromUri('http://127.0.0.1:8888/weights/')
    await faceapi.nets.faceRecognitionNet.loadFromUri('http://127.0.0.1:8888/weights/')

    await faceapi.loadFaceLandmarkModel('http://127.0.0.1:8888/weights/')
    await faceapi.loadFaceExpressionModel('http://127.0.0.1:8888/weights/')

    const input = document.getElementById('image')

    // 画布
    let canvas = faceapi.createCanvasFromMedia(input)
    const box = document.getElementById('box')
    box.prepend(canvas)
    const displaySize = {width:input.width,height:input.height}
    faceapi.matchDimensions(canvas,displaySize)

    // 获取图片中的人脸特征
    const results = await faceapi.detectAllFaces(input).withFaceLandmarks().withFaceExpressions()
    faceapi.matchDimensions(canvas, input)

    const resizedResults = faceapi.resizeResults(results, input)
    const minConfidence = 0.05
    faceapi.draw.drawDetections(canvas, resizedResults)
    faceapi.draw.drawFaceExpressions(canvas, resizedResults, minConfidence)

    closeLoading()
}